import { getSkillCollectionList, getSkillList } from '~/api/skill'
import { useUserStore } from '~/stores/user'

export const useCollections = () => {
    const userStore = useUserStore()
    const list = ref([])
    onMounted(() => {
        getSkillCollectionList({ user_id: userStore.userInfo?.id }).then(
            (res) => {
                list.value = res || []
            }
        )
    })

    return {
        list
    }
}

export const useRecommend = () => {
    const list = ref([])
    onMounted(async () => {
        const getSidebarList = async () => {
            let _sidebarList = await getSkillList({
                recommend: 1
            })
            _sidebarList = _sidebarList
                .filter((f) => {
                    return f.skill.length
                })
                .map((m) => {
                    return m.skill
                })
            list.value = _sidebarList.flat()
        }
        await getSidebarList()
    })

    return {
        list
    }
}
